package com.yixun.qfbao.util;

import com.yixun.qfbao.model.Company;
import com.yixun.qfbao.model.ReportExternal;
import com.yixun.qfbao.model.dto.ReportExternalDto;
import org.apache.commons.lang.StringUtils;

public class ReportExternalConvert {
	
	public static ReportExternal convertDTO2Model(ReportExternalDto dto){
		if(null==dto){
			return new ReportExternal();
		}
		ReportExternal model =new ReportExternal();
		model.setId(dto.getId());
		model.setIsDeleted(dto.getIsDeleted());
		model.setPremiseId(dto.getPremiseId());
		model.setPremisesUuid(dto.getPremisesUuid());
		model.setReportId(dto.getReportId());
		model.setReportUuid(dto.getReportUuid());
		model.setSysId(dto.getSysId());
		model.setUpdateTime(dto.getUpdateTime());
		model.setCreateTime(dto.getCreateTime());
		return model;
	}
	
    public static ReportExternalDto convertModel2DTO(ReportExternal model){
    	if(null==model){
			return new ReportExternalDto();
		}
    	ReportExternalDto dto =new ReportExternalDto();
    	dto.setId(model.getId());
    	dto.setIsDeleted(model.getIsDeleted());
		dto.setPremiseId(model.getPremiseId());
		dto.setPremisesUuid(model.getPremisesUuid());
		dto.setReportId(model.getReportId());
		dto.setReportUuid(model.getReportUuid());
		dto.setSysId(model.getSysId());
		dto.setUpdateTime(model.getUpdateTime());
		dto.setCreateTime(model.getCreateTime());
		return dto;
	}

	/**
	 *  M2查重开关
	 * @param devCompany  渠道商公司信息
	 * @param projectCodeM2 楼盘绑定M2项目code
	 * @return
	 */
	public static boolean repeatSwitchForM2(Company devCompany, String projectCodeM2){
		boolean repeatSwitch = true;
		if(devCompany != null && "1".equals(devCompany.getLinkM2())){
			// 是否开启校验M2重复的开关
			if(StringUtils.isEmpty(devCompany.getCheckM2Repeat()) || !"1".equals(devCompany.getCheckM2Repeat())){
				repeatSwitch = false;
			}
			if(StringUtils.isEmpty(devCompany.getMerchantCode()) || StringUtils.isEmpty(projectCodeM2)){
				repeatSwitch = false;
			}
		}else{
			repeatSwitch = false;
		}
		return repeatSwitch;
	}

}
